home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wsanet8a / wsanet / src / netsrvr.c < prev    next >
C/C++ Source or Header  |  1996-04-08  |  21KB  |  725 lines

  1. /* NetSrvr.C - WinSock NetServer Control for VB/VC++
  2.   - WinSock V1.1 required
  3.   - Visual Basic 1.0 required, 2.0+ preferred (tested only on 3.0)
  4.  
  5.    Author: Ian Blenke
  6.  
  7. In this document, VBX refers to the actual Visual Basic control distributed
  8. with and based on this WSANET project, and author refers to Ian Blenke. The
  9. author cannot be held responsible for damages, expressed or implied, for the
  10. use of this software. No commercial use can be made of this product without
  11. the consent of the author. No profit of any kind can be made on the sale or
  12. distribution of this program. If you wish to distribute this program with
  13. other samples of WinSock programming, you must first contact the author so
  14. that he can keep accurate records of its usage; no charge may be made for
  15. this project's availability other than the cost of the physical medium used
  16. to store it on and any processing costs. If you writany programs based on
  17. this source code, including parts of this source code, or in some way derived
  18. from this source code, you may not sell them for any profit without the
  19. written consent of the author. If you incorporate this VBX into a public
  20. dain program althe author requires is a notification that "The NetClient
  21. control was written by Ian Blenke" and some form of notification that his name
  22. was used in the public domain software distribution. No profit of any kind,
  23. shareware/commercial or otherwise, may be made for software based on this VBX
  24. without the written consent of the author. This does not represent a contract
  25. on the part of the author. If any issues cannot clearly be resolved by reading
  26. this text, immediately contact the author.
  27.  
  28. The VBX control distributed with this project must be distributed with your
  29. programs free of charge. You cannot charge money for any program based on the
  30. VBX without the written consent of the author.
  31.  
  32. Notes:
  33.  
  34. If you have any bug reports and/or source patches... By all means, tell me! I
  35. would be glad to help keep this code up to date. Do not, however, modify this
  36. source in any way and re-distribute it without the author's knowledge. Follow
  37. the above Copyright, and all will be well.
  38.  
  39. I don't like such agreements, but in today's world of lawyers and lawbreakers,
  40. I have little other choice. Enjoy!
  41.  
  42. (This is meant to scare code "scalpers". Those that are actually learning C
  43.  programming for Visual Basic controls and WinSock applications are free to
  44.  adapt any of the ideas of this code. Remember, new code should be better
  45.  code, so "adapt" this, do NOT copy it.)
  46. */
  47.  
  48. #define NetSrvr_C
  49. #include "WSANet.H"
  50. #include "NetSrvr.H"
  51.  
  52.     // Debugging macro's/functions
  53. #ifdef DEBUG_BUILD
  54. static char szErrors[256];
  55.  
  56. VOID DEBUGNETS(LPSTR lpString)
  57. {
  58.  wsprintf((LPSTR)szErrors, (LPSTR)"NetServer: %s\n\r", lpString);
  59.  OutputDebugString( (LPSTR)szErrors );
  60. }
  61. #else
  62. #define DEBUGNETS( parm )
  63. #endif /* DEBUG_BUILD */
  64.  
  65.  
  66. /* LONG CALLBACK _export NetServerCtlProc(HCTL, HWND, UINT, WPARAM, LPARAM);
  67.     Purpose: To handle the VBX messages
  68. */
  69. LONG CALLBACK _export NetServerCtlProc(HCTL hCtl, HWND hWnd, UINT Msg,
  70.                                        WPARAM wParam, LPARAM lParam)
  71. {
  72.  LPNETSERVER lpNetServer;
  73.  
  74.  lpNetServer=(LPNETSERVER)VBDerefControl(hCtl);
  75.  
  76.  switch(Msg)
  77.  {
  78.  
  79. #ifdef DESIGN_TIME
  80.     // The MODEL want's to know our default size
  81.   case VBM_GETDEFSIZE:
  82.   {
  83.    BITMAP bmp;
  84.    HBITMAP hBitmap;
  85.  
  86.    DEBUGNETS("VBM_GETDEFSIZE[2.0] Begin\n\r");
  87.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_SERVER));
  88.    if(hBitmap)
  89.    {
  90.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  91.     DeleteObject(hBitmap);
  92.     DEBUGNETS((LPSTR)"VBM_GETDEFSIZE[2.0] End\n\r");
  93.     return(MAKELONG(bmp.bmWidth, bmp.bmHeight));
  94.    }
  95.    DEBUGNETS((LPSTR)"VBM_GETDEFSIZE[2.0] Allowing DefVBProc to handle\n\r");
  96.   }
  97.   break;
  98.  
  99.     // The re-size message - only in design time
  100.   case WM_SIZE:
  101.   {
  102.    BITMAP bmp;
  103.    HBITMAP hBitmap;
  104.    RECT rect;
  105.    POINT pos;
  106.  
  107.    DEBUGNETS((LPSTR)"WM_SIZE Start");
  108.    GetWindowRect(hWnd, (RECT FAR *)&rect);
  109.    pos.x=rect.left;
  110.    pos.y=rect.top;
  111.    ScreenToClient((HWND)GetWindowWord(hWnd, GWW_HWNDPARENT),
  112.                   (POINT FAR *)&pos);
  113.  
  114.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_SERVER));
  115.    if(hBitmap)
  116.    {
  117.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  118.     MoveWindow(hWnd, pos.x, pos.y, bmp.bmWidth, bmp.bmHeight,
  119.                SWP_NOZORDER | SWP_NOMOVE);
  120.     DeleteObject(hBitmap);
  121.     DEBUGNETS((LPSTR)"WM_SIZE End");
  122.     return(0);
  123.    }
  124.    DEBUGNETS((LPSTR)"WM_SIZE End - Bitmap load failure!");
  125.   }
  126.   break;
  127.  
  128.  
  129.     // The paint message - only design time!
  130.   case WM_PAINT:
  131.   {
  132.    PAINTSTRUCT ps;
  133.    BITMAP bmp;
  134.    RECT rect;
  135.    HBITMAP hBitmap,
  136.            hOldBitmap;
  137.    HDC  hdcMem;
  138.  
  139.    DEBUGNETS((LPSTR)"WM_PAINT Start");
  140.    if(VBGetMode()==MODE_RUN) break;
  141.  
  142.    GetWindowRect(hWnd, (RECT FAR *)&rect);
  143.    BeginPaint(hWnd, (PAINTSTRUCT FAR *)&ps);
  144.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_SERVER));
  145.    if(hBitmap)
  146.    {
  147.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  148.     hdcMem = CreateCompatibleDC(ps.hdc);
  149.     if(hdcMem)
  150.     {
  151.      hOldBitmap=SelectObject(hdcMem, hBitmap);
  152.      BitBlt(ps.hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMem,
  153.             0, 0, SRCCOPY);
  154.      SelectObject(hdcMem, hOldBitmap);
  155.      DeleteDC(hdcMem);
  156.     }
  157.     DeleteObject(hBitmap);
  158.    }
  159.    EndPaint(hWnd, (PAINTSTRUCT FAR *)&ps);
  160.    DEBUGNETS((LPSTR)"WM_PAINT End");
  161.   }
  162.   break;
  163. #endif // DESIGN_TIME
  164.  
  165.  
  166.     // The control is closing - free everything.
  167.   case WM_NCDESTROY:
  168.   {
  169.    DEBUGNETS((LPSTR)"WM_NCDESTROY Begin");
  170.  
  171.    if(lpNetServer->sSocket != SOCKET_ERROR)
  172.    {
  173.     netCloseSocket(hWnd, lpNetServer->sSocket);
  174.     lpNetServer->bListen=FALSE;
  175.     lpNetServer->sSocket=(SOCKET)SOCKET_ERROR;
  176.    }
  177.  
  178.    lpNetServer->sLocalPort = 0;
  179.    lpNetServer->sErrorNumber = 0;
  180.    lpNetServer->sQueueSize = 0;
  181.    DEBUGNETS((LPSTR)"WM_NCDESTROY End");
  182.   }
  183.   break; // WM_NCDESTROY
  184.  
  185.  
  186.   // A New control has been created/loaded
  187.   case VBM_CREATED:
  188.   {
  189.    DEBUGNETS((LPSTR)"VBM_CREATED Begin");
  190.  
  191.    lpNetServer->sLocalPort = 0;
  192.    lpNetServer->sSocket = SOCKET_ERROR;
  193.    lpNetServer->sErrorNumber = 0;
  194.    lpNetServer->sQueueSize = 0;
  195.    lpNetServer->bListen = FALSE;
  196.  
  197.    if(VBGetMode()==MODE_RUN)
  198.    {
  199.     ShowWindow(hWnd, SW_HIDE);
  200.    }
  201.    else
  202.    {
  203.     ShowWindow(hWnd, SW_SHOWNA);
  204.    }
  205.  
  206.    DEBUGNETS((LPSTR)"VBM_CREATED End");
  207.    return(ERR_None);
  208.   } // VBM_CREATED
  209.  
  210.  
  211. #ifdef DESIGN_TIME
  212.     // Here is how to implement a dialog box property!
  213.   case VBM_INITPROPPOPUP:
  214.   {
  215.    switch(wParam)
  216.    {
  217.     case IPROP_NETSERVER_ABOUT:
  218.     {
  219.      DEBUGNETS((LPSTR)"VBM_INITPROPPOPUP: About - Begin");
  220.  
  221.      if(bDialogInUse) return(NULL);
  222.      bDialogInUse = TRUE;
  223.      hDialogHwnd=CreateWindow(CLASS_ABOUTPOPUP, NULL,
  224.             WS_POPUP,
  225.             0, 0, 0, 0,
  226.             NULL, NULL,
  227.             hModDLL, NULL);
  228.      DEBUGNETS((LPSTR)"VBM_INITPROPPOPUP: About - End");
  229.      return(hDialogHwnd);
  230.     }
  231.     break;
  232.    }
  233.   }
  234.   break;
  235. #endif // DESIGN_TIME
  236.  
  237.  
  238. /**********************************************************************
  239.  ***                        SET PROPERTY                            ***
  240.  **********************************************************************/
  241.   case VBM_SETPROPERTY:
  242.   {
  243.    ERR err;
  244. #ifdef DEBUG_BUILD
  245.    char szError[128];
  246.  
  247.    wsprintf((LPSTR)szError, (LPSTR)"VBM_SETPROPERTY: #%d - Begin",
  248.              wParam);
  249.    DEBUGNETS((LPSTR)szError);
  250. #endif /* DEBUG_BUILD */
  251.  
  252.    switch(wParam)
  253.    {
  254.  
  255.     /****************** SET: Socket *********************/
  256.     // Can't set!!!
  257.     case IPROP_NETSERVER_SOCKET:
  258.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"Socket"));
  259.  
  260.  
  261.     /****************** SET: ErrorMessage ****************/
  262.     // Can't set!!!
  263.     case IPROP_NETSERVER_ERRORMESSAGE:
  264.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"ErrorMessage"));
  265.  
  266.  
  267.     /****************** SET: Version ********************/
  268.     // Can't set!!!
  269.     case IPROP_NETSERVER_VERSION:
  270.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"Version"));
  271.  
  272.  
  273.     /****************** SET: Listen *********************/
  274.     // User is trying to listen() for incoming connections
  275.     // This is the most complex part of the program
  276.     case IPROP_NETSERVER_LISTEN:
  277.     {
  278.      SOCKET sSocket;
  279.      LONG lNonBlocking = TRUE;
  280.      SOCKADDR_IN saLocal;
  281.      int iError;
  282.      BOOL bReuseAddr = TRUE;
  283.  
  284.      DEBUGNETS((LPSTR)"SET: Listen - Begin");
  285.  
  286.      if((lpNetServer->bListen) && *(BOOL *)&lParam)
  287.      {
  288.       DEBUGNETS((LPSTR)"SET: Listen - End - Already listening");
  289.       return(netReturnError(WSAERR_AlreadyConn, WSAERR_AlreadyConn, NULL));
  290.      }
  291.  
  292.      if(!(lpNetServer->bListen) && !*(BOOL *)&lParam)
  293.      {
  294.       DEBUGNETS((LPSTR)"SET: Listen - End - Pointless!");
  295.       return(ERR_None);
  296.      }
  297.  
  298.      if((lpNetServer->bListen) && !*(BOOL *)&lParam)
  299.      {
  300.       netCloseSocket(hWnd, lpNetServer->sSocket);
  301.       lpNetServer->bListen=FALSE;
  302.       lpNetServer->sSocket=(SOCKET)SOCKET_ERROR;
  303.       DEBUGNETS((LPSTR)"SET: Listen - End - Stopped listening!");
  304.       return(ERR_None);
  305.      }
  306.  
  307.         // In the odd chance that a socket remains that is
  308.         // listening, close it!
  309.      if(lpNetServer->sSocket != SOCKET_ERROR)
  310.      {
  311.       netCloseSocket(hWnd, lpNetServer->sSocket);
  312.       lpNetServer->sSocket=(SOCKET)SOCKET_ERROR;
  313.      }
  314.  
  315.         // Create a new socket
  316.      sSocket = socket(PF_INET, SOCK_STREAM, 0);
  317.  
  318.      if( sSocket==INVALID_SOCKET )
  319.      {
  320.       return(NetServerError(hCtl, WSAGetLastError()));
  321.      }
  322.  
  323.         // Set up asyncronous messages. Remember, child
  324.         // accept()ed sockets will have this same mask.
  325.      if(WSAAsyncSelect(sSocket, hWnd, CM_NETACTIVITY,
  326.           FD_ACCEPT | FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE)
  327.         == SOCKET_ERROR)
  328.      {
  329.       NetServerError(hCtl, WSAGetLastError());
  330.       closesocket(sSocket);
  331.       return(ERR_None);
  332.      }
  333.  
  334.         // Save the socket
  335.      lpNetServer->sSocket=(SOCKET)sSocket;
  336.  
  337.         // If Listen = 2 then DON'T USE REUSE_ADDR!
  338.      if(*(int *)&lParam != 2)
  339.      {
  340.       setsockopt(sSocket, SOL_SOCKET, SO_REUSEADDR,
  341.                 (char FAR *)&bReuseAddr, sizeof(BOOL));
  342.      }
  343.         // Bind the socket
  344.      DEBUGNETS((LPSTR)"SET: Listen - bind() - Begin");
  345.      saLocal.sin_family=AF_INET;
  346.      saLocal.sin_addr.s_addr=INADDR_ANY;
  347.      saLocal.sin_port=htons(lpNetServer->sLocalPort);
  348.  
  349.      if(bind(sSocket, (LPSOCKADDR)&saLocal,
  350.         sizeof(saLocal))==SOCKET_ERROR)
  351.      {
  352.       NetServerError(hCtl, WSAGetLastError());
  353.       closesocket(sSocket);
  354.       lpNetServer->sSocket=(SOCKET)SOCKET_ERROR;
  355.       return(ERR_None);
  356.      }
  357.      DEBUGNETS((LPSTR)"SET: Listen - bind() - End");
  358.  
  359.      DEBUGNETS((LPSTR)"SET: Listen - listen() - Begin");
  360.         // Listen for incoming
  361.      if(listen(sSocket, lpNetServer->sQueueSize)==SOCKET_ERROR)
  362.      {
  363.       NetServerError(hCtl, WSAGetLastError());
  364.       closesocket(sSocket);
  365.       lpNetServer->sSocket=(SOCKET)SOCKET_ERROR;
  366.       return(ERR_None);
  367.      }
  368.      DEBUGNETS((LPSTR)"SET: Listen - listen() - End");
  369.  
  370.      lpNetServer->bListen = TRUE;
  371.  
  372.      DEBUGNETS((LPSTR)"SET: Listen - End");
  373.      return(ERR_None);
  374.     } // IPROP_NETSERVER_LISTEN
  375.  
  376.  
  377.     /****************** SET: QueueSize *****************/
  378.     // Only set if we aren't listening
  379.     case IPROP_NETSERVER_QUEUESIZE:
  380.     {
  381.      DEBUGNETS((LPSTR)"SET: QueueSize - Begin");
  382.      if(!lpNetServer->bListen)
  383.         lpNetServer->sQueueSize=*(SHORT *)&lParam;
  384.      DEBUGNETS((LPSTR)"SET: QueueSize - End");
  385.      return(ERR_None);
  386.     } // IPROP_NETSERVER_QUEUESIZE
  387.  
  388.  
  389.     /****************** SET: LocalPort ******************/
  390.     // Only set if we aren't listening
  391.     case IPROP_NETSERVER_LOCALPORT:
  392.     {
  393.      DEBUGNETS((LPSTR)"SET: LocalPort - Begin");
  394.      if(!lpNetServer->bListen)
  395.         lpNetServer->sLocalPort=*(SHORT *)&lParam;
  396.      DEBUGNETS((LPSTR)"SET: LocalPort - End");
  397.      return(ERR_None);
  398.     } // IPROP_NETSERVER_LOCALPORT
  399.  
  400.  
  401.     /****************** SET: LocalService ***************/
  402.     // Handle Setting of LocalService
  403.     case IPROP_NETSERVER_LOCALSERVICE:
  404.     {
  405.      LPSTR lpLocalService;
  406.      LPSERVENT lpseServEnt;
  407.  
  408.      DEBUGNETS((LPSTR)"SET: LocalService - Begin");
  409.      if(!lParam)
  410.      {
  411.       lpNetServer->sLocalPort = 0;
  412.       return( netReturnError( VBERR_INVALIDPROPERTYVALUE, 0, NULL));
  413.      }
  414.  
  415.      if(!lpNetServer->bListen)
  416.      {
  417.       lpLocalService=*(LPSTR *)&lParam;
  418.  
  419.         // Get service by name, but don't do families... yet?
  420.       lpseServEnt = getservbyname( lpLocalService, NULL);
  421.  
  422.       if(lpseServEnt)
  423.       {
  424.         // Copy out the port number
  425.        lpNetServer->sLocalPort = ntohs(lpseServEnt->s_port);
  426.       }
  427.       else
  428.       {
  429.        lpNetServer->sLocalPort = 0;
  430.        DEBUGNETS((LPSTR)"SET: LocalService - getservbyname() returned NULL!");
  431.        return(NetServerError( hCtl, WSAGetLastError()));
  432.       }
  433.      }
  434.      DEBUGNETS((LPSTR)"SET: LocalService - End");
  435.      return(ERR_None);
  436.     } // IPROP_NETSERVER_LOCALSERVICE
  437.  
  438.  
  439.     /****************** SET: Debug **********************/
  440.     // Set SO_DEBUG
  441.     case IPROP_NETSERVER_DEBUG:
  442.     {
  443.      BOOL fDebug = *(BOOL *)&lParam;
  444.  
  445.      DEBUGNETS((LPSTR)"SET: Debug - Begin");
  446.  
  447.      if((lpNetServer->sSocket != 0) &&
  448.         (lpNetServer->sSocket != SOCKET_ERROR))
  449.      {
  450.       if(setsockopt(lpNetServer->sSocket, SOL_SOCKET, SO_DEBUG,
  451.                     (LPSTR)&fDebug, sizeof(fDebug))
  452.                != SOCKET_ERROR)
  453.       {
  454.        DEBUGNETS((LPSTR)"SET: Debug - End - Ok");
  455.        return(ERR_None);
  456.       }
  457.       else return(NetServerError(hCtl, WSAGetLastError()));
  458.      }
  459.      return(netReturnError(WSAERR_NotConn, WSAERR_NotConn, NULL));
  460.     }
  461.     break;
  462.    }
  463.   }
  464.   break;
  465.  
  466.  
  467. /**********************************************************************
  468.  ***                        GET PROPERTY                            ***
  469.  **********************************************************************/
  470.   case VBM_GETPROPERTY:
  471.   {
  472. #ifdef DEBUG_BUILD
  473.    char szError[128];
  474.  
  475.    wsprintf((LPSTR)szError, (LPSTR)"VBM_GETPROPERTY: #%d: Begin",
  476.             wParam);
  477.    DEBUGNETS((LPSTR)szError);
  478. #endif /* DEBUG_BUILD */
  479.  
  480.    switch(wParam)
  481.    {
  482.  
  483.     /****************** GET: LocalService ***************/
  484.     case IPROP_NETSERVER_LOCALSERVICE:
  485.     {
  486.      HSZ hszTemp;
  487.      LPSERVENT lpseServEnt;
  488.      BOOL bClear = FALSE;
  489.  
  490.      DEBUGNETS((LPSTR)"GET: LocalService - Begin");
  491.  
  492.      lpseServEnt = getservbyport( htons(lpNetServer->sLocalPort), NULL);
  493.      if(lpseServEnt)
  494.      {
  495.       if(lpseServEnt->s_name)
  496.       {
  497.        hszTemp = VBCreateHsz((_segment)hCtl, lpseServEnt->s_name);
  498.       }
  499.       else bClear = TRUE;
  500.      }
  501.      else
  502.      {
  503.       bClear = TRUE;
  504.       NetServerError(hCtl, WSAGetLastError());
  505.      }
  506.  
  507.      if(bClear)
  508.      {
  509.       char cChar = '\0';
  510.  
  511.       hszTemp = VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  512.      }
  513.  
  514.      *(*(LPHSZ *)&lParam) = hszTemp;
  515.  
  516.      DEBUGNETS((LPSTR)"GET: LocalService - End");
  517.      return(ERR_None);
  518.     } // IPROP_NETSERVER_LOCALSERVICE
  519.  
  520.  
  521.     /****************** GET: ErrorMessage ***************/
  522.     case IPROP_NETSERVER_ERRORMESSAGE:
  523.     {
  524.      char szString[256];
  525.      HSZ  hszTemp;
  526.      char cChar;
  527.      int iError;
  528.  
  529.      DEBUGNETS((LPSTR)"GET: ErrorMessage - Begin");
  530.  
  531.      iError=lpNetServer->sErrorNumber;
  532.      if(!LoadString(hModDLL, iError, (LPSTR)szString,
  533.                 sizeof(szString)))
  534.      {
  535.       wsprintf((LPSTR)szString, (LPSTR)"Unknown Error #%d",
  536.                iError);
  537.      }
  538.  
  539. #ifdef DESIGN_TIME
  540.      DEBUGNETS((LPSTR)szString);
  541. #endif
  542.  
  543.      // Set the error message text
  544.  
  545.      cChar='\0';
  546.      hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)szString);
  547.      DEBUGNETS((LPSTR)"GET: ErrorMessage - Created new error string");
  548.      if(!hszTemp) hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  549.  
  550.      *(*(LPHSZ *)&lParam) = hszTemp;
  551.  
  552.      DEBUGNETS((LPSTR)"GET: ErrorMessage - End");
  553.      return(ERR_None);
  554.     } // IPROP_NETSERVER_ERRORMESSAGE
  555.  
  556.  
  557.     /****************** GET: Version ********************/
  558.     // Get NetServer version string...
  559.     case IPROP_NETSERVER_VERSION:
  560.     {
  561.      HSZ hszTemp;
  562.      char cChar = '\0';
  563.  
  564.      DEBUGNETS((LPSTR)"GET: Version - Begin");
  565.  
  566.      hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)WSANET_VERSION_TEXT);
  567.      if(!hszTemp) hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  568.  
  569.      *(*(LPHSZ *)&lParam) = hszTemp;
  570.      DEBUGNETS((LPSTR)WSANET_VERSION_TEXT);
  571.  
  572.      DEBUGNETS((LPSTR)"GET: Version - End");
  573.      return(ERR_None);
  574.     } // IPROP_NETSERVER_VERSION
  575.  
  576.  
  577.     /****************** GET: Debug **********************/
  578.     // Get SO_DEBUG
  579.     case IPROP_NETSERVER_DEBUG:
  580.     {
  581.      BOOL fDebug;
  582.      int iSize = sizeof(fDebug);
  583.  
  584.      DEBUGNETS((LPSTR)"GET: Debug - Begin");
  585.  
  586.      if((lpNetServer->sSocket != 0) &&
  587.         (lpNetServer->sSocket != SOCKET_ERROR))
  588.      {
  589.       if(getsockopt(lpNetServer->sSocket, SOL_SOCKET, SO_DEBUG,
  590.                     (LPSTR)&fDebug, (int FAR *)&iSize)
  591.            != SOCKET_ERROR)
  592.       {
  593.        *(*(SHORT FAR **)&lParam)=(SHORT)fDebug;
  594.        DEBUGNETS((LPSTR)"GET: Debug - End - SO_DEBUG returned");
  595.        return(ERR_None);
  596.       }
  597.      }
  598.      *(*(SHORT FAR **)&lParam)=0;
  599.      DEBUGNETS((LPSTR)"GET: Debug - End - False returned");
  600.      return(ERR_None);
  601.     } // IPROP_NETSERVER_DEBUG
  602.  
  603.  
  604.     /****************** GET: DEFAULT handler! ***********/
  605.     default:
  606.     {
  607.      DEBUGNETS((LPSTR)"GET: Property not handled");
  608.     }
  609.     break;
  610.    }
  611.    DEBUGNETS((LPSTR)"VBM_GETPROPERTY: End");
  612.   }
  613.   break;
  614.  
  615.  
  616. /**********************************************************************
  617.  ***                        GET PROPERTY HSZ                        ***
  618.  **********************************************************************/
  619. #ifdef DESIGN_TIME
  620.     // Set the About propery to display "About NetServer"
  621.   case VBM_GETPROPERTYHSZ:
  622.   {
  623.    DEBUGNETS((LPSTR)"VBM_GETPROPERTYHSZ Begin");
  624.    switch(wParam)
  625.    {
  626.     case IPROP_NETSERVER_ABOUT:
  627.     {
  628.      DEBUGNETS((LPSTR)"GETPROPERTYHSZ: About");
  629.      *(*(LPHSZ *)&lParam) = VBCreateHsz((_segment) hCtl, (LPSTR)STRING_ABOUTTEXT);
  630.      return(ERR_None);
  631.     }
  632.    }
  633.    DEBUGNETS((LPSTR)"VBM_GETPROPERTYHSZ End");
  634.   }
  635.   break;
  636.  
  637. /**********************************************************************
  638.  ***                   CONTEXT SENSITIVE HELP                       ***
  639.  **********************************************************************/
  640.   case VBM_HELP:
  641.   {
  642. #ifdef DEBUG_BUILD
  643.    char szError[128];
  644.  
  645.    DEBUGNETS((LPSTR)"VBM_HELP: Begin");
  646.    wsprintf((LPSTR)szError, (LPSTR)"VBM_HELP: Prop. #%d",
  647.              wParam );
  648.    DEBUGNETS((LPSTR)szError);
  649. #endif // DEBUG_BULD
  650.  
  651.    if(bHelpStdPropEvt(wParam, (LPMODEL)lParam))
  652.         break;
  653.    else return(DisplayHelpTopic(TOPIC_CONTROL_NETSERVER, wParam,
  654.                                 (LPMODEL)lParam));
  655.    DEBUGNETS((LPSTR)"VBM_HELP: Standard handler allowed");
  656.   }
  657.   break;
  658. #endif // DESIGN_TIME
  659.  
  660.  
  661.     // **** The network activity message ****
  662.   case CM_NETACTIVITY:
  663.   {
  664.    DEBUGNETS((LPSTR)"CM_NETACTIVITY");
  665.  
  666.    return(netServerAsyncProc(hCtl, hWnd, wParam, lParam));
  667.   }
  668.  
  669.  }
  670.  return(VBDefControlProc(hCtl, hWnd, (USHORT)Msg, (USHORT)wParam,
  671.         (LONG)lParam));
  672. } /* NetServerCtlProc() */
  673.  
  674.  
  675. /* ERR NetServerError(HCTL hCtl, int);
  676.     Purpose: To set a VB error level and string to any errors
  677. */
  678. ERR NetServerError(HCTL hCtl, int iError)
  679. {
  680.  char szString[256];
  681.  LPNETSERVER lpNetServer;
  682.  
  683.  wsprintf((LPSTR)szString, (LPSTR)"NetServerError(%d) - Begin", iError);
  684.  DEBUGNETS((LPSTR)szString);
  685.  
  686.  if(!iError) return(ERR_None);
  687.  
  688.  if(iError == WSANO_DATA) return(ERR_None);
  689.  
  690.  lpNetServer=(LPNETSERVER)VBDerefControl(hCtl);
  691.  lpNetServer->sErrorNumber=(SHORT)iError;
  692.  
  693.  DEBUGNETS((LPSTR)"NetServerError() - Fire OnError()");
  694.  
  695.  return(serverFireOnError(hCtl));
  696. } /* NetServerError() */
  697.  
  698.  
  699. /* ERR serverFireOnError(HCTL);
  700.     Purpose: To fire the OnError event.
  701.     Given:   The control handle
  702.     Returns: Any error condition.
  703. */
  704. ERR serverFireOnError(HCTL hCtl)
  705. {
  706.  ONERRORPARMS Parameters;
  707.  LPNETSERVER lpNetServer;
  708.  SHORT       sErrorNumber;
  709.  
  710.     // Dereference the control so we can look inside
  711.     // Becomes invalid after the first VBLockHsz() below!
  712.  DEBUGNETS((LPSTR)"serverFireOnError() - Begin");
  713.  lpNetServer=(LPNETSERVER)VBDerefControl(hCtl);
  714.  
  715.  sErrorNumber=lpNetServer->sErrorNumber;
  716.  
  717.     // Set the error number
  718.  Parameters.ErrorNumber=(SHORT FAR *)&sErrorNumber;
  719.  
  720.  return(VBFireEvent(hCtl, IEVENT_NETSERVER_ONERROR, (LPVOID)&Parameters));
  721. } /* serverFireOnError() */
  722.  
  723.  
  724.  
  725.